<template>
  <div id="login">
    <h2>贝壳找房</h2>
    <van-form @submit="onSubmit">
      <!-- usename 对应 账户输入框 -->
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <!-- password 对应 密码输入框 -->
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit">登录</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      username: 'root',
      password: 'root',
    };
  },
  methods: {
    onSubmit(values) {

        axios.get('/login.json',{params : values}).then((response) => {
           if(response.data.success) {

             this.$store.commit("updatelogin", true);

             this.$router.push("/index")
           } else {
             alert("登录失败")
           }
        })

      },
  },
};
</script>